package com.shaw.workrecord.controller;

import com.shaw.workrecord.entity.ResponseBean;
import com.shaw.workrecord.pojo.game.request.RoomMemberAddRequest;
import com.shaw.workrecord.pojo.game.response.RoomMemberResponse;
import com.shaw.workrecord.service.IRoomMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jiangjunhui
 * @description
 * @date 2022/9/15 14:04
 */
@RestController
@Api(tags = "房间玩家管理")
@Validated
public class RoomMemberController {

    @Autowired
    private IRoomMemberService service;

    @ApiOperation("获取房间玩家列表")
    @GetMapping("/roomMember/{roomId}")
    public ResponseBean<List<RoomMemberResponse>> getMemberList(@PathVariable("roomId") Long roomId) {
        return ResponseBean.success(service.getMemberList(roomId));
    }

    @PostMapping("/roomMember")
    @ApiOperation("加入房间")
    public ResponseBean<Boolean> addMember(@RequestBody RoomMemberAddRequest request) {
        if (service.addMember(request.getRoomId())) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("加入房间失败");
    }

    @DeleteMapping("/roomMember/{roomId}")
    @ApiOperation("加入房间")
    public ResponseBean<Boolean> removeMember(@PathVariable("roomId") Long roomId) {
        if (service.removeMember(roomId)) {
            return ResponseBean.success(true);
        }
        return ResponseBean.failure("加入房间失败");
    }
}
